API Documentation
Public Member Functions | List of all members
nkTasks::Thread Class Referencefinal

Symbolizes a thread. Base block to submit off-thread nkTasks::Task in this component. More...

Public Member Functions

 Thread ()
 
 ~Thread ()
 
ThreadId getThreadId () const
 
void setParentScheduler (Scheduler *value)
 
ThreadSubmittedWork addTask (Task *task)
 
bool cancelTask (const ThreadSubmittedWork &submittedWork)
 
void askAbort ()
 
void join ()
 
void askAbortAndJoin ()
 
void run ()
 

Detailed Description

Symbolizes a thread. Base block to submit off-thread nkTasks::Task in this component.

Constructor & Destructor Documentation

◆ Thread()

nkTasks::Thread::Thread ( )

Constructor.

◆ ~Thread()

nkTasks::Thread::~Thread ( )

Destructor.

Member Function Documentation

◆ getThreadId()

ThreadId nkTasks::Thread::getThreadId ( ) const
Returns
The identifier associated to the thread.

◆ setParentScheduler()

void nkTasks::Thread::setParentScheduler ( Scheduler value)

Allows to set the parent scheduler for a thread.

Parameters
valueThe scheduler marked as a parent.
Remarks
In theory, this function should not be called from external code.

◆ addTask()

ThreadSubmittedWork nkTasks::Thread::addTask ( Task task)

Allows to submit a task to the thread.

Parameters
taskTask to submit.
Returns
Information over the submitted task for later control if needed.

◆ cancelTask()

bool nkTasks::Thread::cancelTask ( const ThreadSubmittedWork submittedWork)

Request a task cancelling.

Parameters
submittedWorkThe information returned from a task submission, identifying the task to cancel.
Returns
Whether the task could be cancelled (true) or not (false).
Remarks
A task that could not be cancelled means that a thread is already processing it. To cancel such a task, it is up to the external code to implement this logic to halt work while in the nkTasks::Task::onWork() function.

◆ askAbort()

void nkTasks::Thread::askAbort ( )

Requests the thread to end. This function won't halt the thread calling it. It merely marks the thread for end of execution.

◆ join()

void nkTasks::Thread::join ( )

Join the thread. First, a call to askAbort() has to be made. This will lock the thread calling this function until joinable thread is done.

◆ askAbortAndJoin()

void nkTasks::Thread::askAbortAndJoin ( )

A shorthand for askAbort() followed by join().

Remarks
Calling this function will lock the thread calling until joinable thread is done. To reduce this effect, it could be possible to call askAbort(), and later call join().

◆ run()

void nkTasks::Thread::run ( )

Starts the thread. Has to be called for the thread to create its context and run.


The documentation for this class was generated from the following file: